package controller;

import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bizlogic.LeaveManager;

import model.EmployeeDTO;
import model.LeaveDTO;

/**
 * Servlet implementation class PersonalLeaveHistoryServlet
 */

public class PersonalLeaveHistoryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public PersonalLeaveHistoryServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		doProcess(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		doProcess(request, response);
	}

	// EDIT HERE HERE HERE HERE BOON
	private void doProcess(HttpServletRequest request,
			HttpServletResponse response) {
	
		HttpSession session = request.getSession();
		EmployeeDTO user = (EmployeeDTO) session.getAttribute("user");
		int id =user.getEmployeeID();
	
		
		LeaveManager Lmanager = new LeaveManager();// bizlogic
		
		ArrayList<LeaveDTO> data = Lmanager.findLeaveHistory(id);	
		// ArrayList<LeaveDTO> data = Lmanager.findAllLeave();
		request.setAttribute("leave", data);
	
		RequestDispatcher rd = request.getRequestDispatcher("PersonalLeaveListing.jsp");
		
		try {
			
			rd.forward(request, response);
			System.out.println("do ok");
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("do error");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("do error");
		}
	}

}
